
#include "ManActiveBuzzer.h"

//方波半周期20*10=200ms
#define  con_tick_period  20

void (*ManActiveBuzzer::digitalWrite)(uint8_t) = 0;


ManActiveBuzzer::ManActiveBuzzer(){
    m_mode=0;
}


void ManActiveBuzzer::setMode(uint8_t mode) {
   m_mode=mode;
}



void ManActiveBuzzer::setPort(bool v) {
    m_v=v;
    digitalWrite(m_v);
}



void ManActiveBuzzer::tick() {
    if(m_mode==0){
        //低电平不响
        setPort(false);
        return;
    }
    if(tickPeriod>0){
        tickPeriod--;
        return;
    }
    tickPeriod = con_tick_period;

    //开始
    if (sound_false == 0)
    {
        sound_ture = m_mode;
        sound_false = m_mode;
        setPort(true);
    }//正在响
    else if (sound_ture)
    {
        //产生一个下降沿,响计数减1
        if (m_v)
        {
            setPort(false);
            sound_ture--;
        }
        else
        {
            setPort(true);
        }
    }//响间隔
    else
    {
        sound_false--;
    }
}
